import React from 'react'
import { Typography, Space } from 'antd';
import TheTable from "@/components/TheTable"
import TheButton from '@/components/TheButton';
const { Text } = Typography;

export default class linkedOrder extends React.PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      orderInfo: props.orderInfo, //数据信息
      columns: [
        {
          title: '订单编号',
          render: (_, record) => {
            return record.refundType ? record.salesReturnId : record.orderId
          }
        },
        {
          title: '类型',
          dataIndex: "refundType",
          key: "refundType",
          render: (text) => {
            return text ? '售后订单' : '普通订单'
          }
        },
        {
          title: '操作',
          render: (_, record) => {
            return <TheButton haspermi={['call:orderListDetails:aboutOrder']} onClick={() => { this.toLinkedOrderDetail(record) }}>查看订单</TheButton>
          }
        }
      ],
      dataSource: [],
    }
  }
  async componentDidMount() {
    await this.getData()
  }
  // 数据处理
  getData = async () => {
    let { orderInfo } = this.props
    if (orderInfo) {
      this.setState({
        dataSource: orderInfo.relationOrderList
      })
    }
  }
  //跳转售后单详情
  toLinkedOrderDetail = (value) => {
    let path = ''
    if (value.refundType) {
      switch (value.refundType) {
        case '1':
          path = '/call/order/afterSaleOrder/refundDetails/' + value.salesReturnId
          break
        case '0':
          path = '/call/order/afterSaleOrder/changeDetails/' + value.salesReturnId
          break
      }
    } else {
      path = '/call/order/orderList/details/' + value.orderId
      // this.props.getRequest(value.orderId)
    }
    if (path && path !== '') {
      this.props.history.push(path)
    }
  }
  render() {
    const { columns, dataSource } = this.state
    return (
      <div >
        <div style={{ fontSize: 14, margin: ' 10px  0', fontWeight: 600 }}>关联订单</div>
        <TheTable dataSource={dataSource} columns={columns} />
      </div>
    )
  }
}